package algorithmCompetition;

import java.util.Scanner;

public class Main {

    static long result = 0;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int[] a2 = new int[n];
        for(int i=0;i<n;i++){
            a[i] = scanner.nextInt();
        }
        for(int i=0;i<n;i++){
            a2[i] = function1(a[i]);
            function2(a2[i],a[i]);
            System.out.println(result);
            result = 0;
        }
    }

    //计算位数
    public static int function1(long n){
        int n2 = 0;
        while (n>0){
            n2++;
            n = n/10;
        }
        return n2;
    }

    //计算结果
    public static void function2(int n,long k){
        long n2 = 0;
        //求前n位的和
        for(int i=1;i<n;i++){
            result =  result + (long)(9*Math.pow(10,i-1)*i);
        }
        //求前n位的值
        for(int i=1;i<n;i++){
            n2 = n2 + (long) (9*Math.pow(10,i-1));
        }
        k = k-n2;
        result = result + k * n;

    }
}
